package com.service.impl;

import com.bean.entity.TestInfo;
import com.bean.pojo.PageAssistant;
import com.dao.TestInfoMapper;
import com.service.TestInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class TestInfoServiceImpl implements TestInfoService {

    @Autowired
    private TestInfoMapper testInfoMapper;
    @Override
    public int save(TestInfo t) throws Exception {
        int insert = testInfoMapper.insert(t);
        if (insert==1) return 1;
        throw new Exception("试卷增加失败！");
    }

    @Override
    public int remove(TestInfo t) throws Exception {
        int delete = testInfoMapper.delete(t);
        if (delete==1) return 1;
        throw new Exception("试卷信息删除失败！");
    }

    @Override
    public int modify(TestInfo t) throws Exception {
        int update = testInfoMapper.update(t);
        if (update==1) return 1;
        throw new Exception("试卷信息修改失败！");
    }

    @Override
    public TestInfo unique(TestInfo t) throws Exception {
        List<TestInfo> select = testInfoMapper.select(t);
        if(select.size()!=1) throw new Exception("您要查询的试卷未找到！");
        return select.get(0);
    }

    @Override
    public List<TestInfo> query(TestInfo t) {
        return testInfoMapper.select(t);
    }

    @Override
    public PageAssistant<TestInfo> queryByPage(Map<String, Object> map, PageAssistant<TestInfo> pa) {
        //查询并设置总记录数
        pa.setCount(testInfoMapper.selectCount(map));

        //添加分页参数
        map.put("startCode",pa.getStartCode());
        map.put("pageSize",pa.getPageSize());

        //查询并设置页面内容
        pa.setItems(testInfoMapper.selectByPage(map));

        return pa;
    }
}
